﻿using Signit.Sdk;
using System;
using System.Collections.Generic;
using Viyi.Util;

namespace SdkSample.Testing
{
    class TestVerify : TestBase
    {
        public override void Test()
        {
            var result = SignitClient.Verify(
                client.Authentication.AppId,
                client.Authentication.SecuretKey,
                new RequestSupplier());

            Log("Verify", result);
        }
    }

    class RequestSupplier : IVerifyRequest
    {
        public byte[] GetBody()
        {
            var s = @"{""event"":""quickSignCompleted"",""target"":{""webhookWsid"":""WSID_HOOK_0000016af3b667ff3eebbcfde3dd0001"",""destination"":""https://webhook.site/b8faacef-e4f6-447a-9d65-90d3a7140844""},""rawData"":""{\""code\"":\""100550100\"",\""links\"":[]}"",""needCallBack"":false}";
            return s.ToByteArray();
        }

        public string ContentType => "application/json";

        public string GetHeader(string key) => headers[key];

        private IDictionary<string, string> headers
            = new Dictionary<string, string>(StringComparer.InvariantCultureIgnoreCase)
        {
            { "x-forwarded-for", "112.44.251.136" },
            { "x-signit-signature", "HmacSHA512 16af1e919633eebbcfde3dd29f1:lYt1B7zt9EG0DXGfx9kHUU0tb3PMpO6dkJUSK7Ffa6vGv/XXqQ2+GOIgIqhjBCWULrn6MpNW8Mv9eS4aWT5lfw==" },
            { "x-signit-scheme", "https" },
            { "x-signit-resource", "" },
            { "x-signit-nonce", "6xZvKtFSyK74hx8ieZlS0T7E" },
            { "x-signit-host", "webhook.site" },
            { "x-signit-event", "QUICK_SIGN_COMPLETED" },
            { "x-signit-date", "Sun May 26 20:38:55 CST 2019" },
        };

        public string GetMethod() => "POST";
    }
}
